<template>
    <div>
        <!-- 登陆等待 -->
        <div v-if="currentStatus==1" style="margin-top:35vh;text-align:center">
            <a-spin size="large" />
            <p style="font-size:15px;margin-top:5px;color:#1890ff;">登陆中...</p>
        </div>
        
        <!-- 结果提示 -->
        <a-result v-if="currentStatus==3" status="403" title="验证失败" sub-title="登陆验证失败，可能登陆信息过期，请返回SSO平台重新登陆或选择密码登陆！">
            <template #extra>
                <a-button @click="toSso" type="primary">
                返回SSO平台
                </a-button>
            </template>
        </a-result>
     </div>
</template>

<script lang='ts'>

import { defineComponent,ref,reactive,toRefs,onBeforeMount,onMounted} from 'vue'
import {useRoute,useRouter} from "vue-router"
import { message } from 'ant-design-vue';
import {login} from "/@/request/api"
import Cookies from "js-cookie"
enum status{
    loading=1,
    success=2,
    fail=3
}
export default defineComponent({
    name: '',
    setup() {
        let route=useRoute(),router=useRouter()
        let currentStatus=ref<status>(0)

        if(route.query.type=='sso'){
            let {sign}=route.query
            currentStatus.value=status.loading
            login({sign}).then((res) => {
                if (res.data.code == 200) {
                    Cookies.set('userInfo', JSON.stringify(res.data.data.user), { expires: 14 });
                    setTimeout(()=>{
                        if(route.query.back){   //如果有回调地址
                            window.location.href=decodeURIComponent(route.query.back as string) 
                        }else{
                           router.push({
                                name: 'home',
                            });
                        }
                    },2000)
                }else{
                    currentStatus.value=status.fail
                }
            })
        }else{
            message.success('请重新登陆');
           // window.location.href='https://sso.yolanda.hk/login?id=1000036'
        }

        let toSso=()=>{
            window.location.href="https://sso.yolanda.hk"
        }

        
        return {
            currentStatus,
            toSso
        }

    }
});
</script>
<style lang='scss' scoped>

</style>